<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>统计字符串出现的次数</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.mb-substitute-character.html">« mb_substitute_character</a></li>
      <li style="float: right;"><a href="function.mb-substr.html">mb_substr »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.mbstring.html">多字节字符串 函数</a></li>
    <li>统计字符串出现的次数</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mb-substr-count" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_substr_count</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mb_substr_count</span> &mdash; <span class="dc-title">统计字符串出现的次数</span></p>

 </div>
   
 <div class="refsect1 description" id="refsect1-function.mb-substr-count-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_substr_count</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$haystack</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$needle</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encoding</code><span class="initializer"> = mb_internal_encoding()</span></span>): <span class="type">int</span></div>

  <p class="para rdfs-comment">
   统计子字符串 <code class="parameter">needle</code> 出现在<span class="type"><span class="type 字符串">字符串</span></span> <code class="parameter">haystack</code> 中的次数。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-substr-count-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">haystack</code></dt>

     <dd>

      <p class="para">
       要检查的<span class="type"><span class="type 字符串">字符串</span></span>。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">needle</code></dt>

     <dd>

      <p class="para">
       待查找的<span class="type"><span class="type 字符串">字符串</span></span>。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">encoding</code></dt>

     <dd>

      <p class="para"><code class="parameter">encoding</code>
参数为字符编码。如果省略或是 <strong><code>null</code></strong>，则使用内部字符编码。</p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mb-substr-count-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   子字符串 <code class="parameter">needle</code> 出现在<span class="type"><span class="type 字符串">字符串</span></span> <code class="parameter">haystack</code> 中的次数。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mb-substr-count-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2585">
    <p><strong>示例 #1 <span class="function"><strong>mb_substr_count()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">mb_substr_count</span><span style="color: #007700">(</span><span style="color: #DD0000">"This&nbsp;is&nbsp;a&nbsp;test"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"is"</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;输出&nbsp;2<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mb-substr-count-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mb-strpos.html" class="function" rel="rdfs-seeAlso">mb_strpos()</a> - 查找字符串在另一个字符串中首次出现的位置</span></li>
    <li class="member"><span class="function"><a href="function.mb-substr.html" class="function" rel="rdfs-seeAlso">mb_substr()</a> - 获取部分字符串</span></li>
    <li class="member"><span class="function"><a href="function.substr-count.html" class="function" rel="rdfs-seeAlso">substr_count()</a> - 计算字串出现的次数</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>